package com.ccsu.joysport.service;

import com.ccsu.joysport.entity.Results;
import com.ccsu.joysport.repository.ResultRepository;
import com.ccsu.joysport.util.JwtUtil;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResultService {
    @Value("${jwt.secret}")
    private String secretKey;

    @Autowired
    private ResultRepository resultRepository;

    @Autowired
    private JwtUtil jwtUtil;

    public List<Results> getResultsByToken(String token) {
        // 解析token并获取学生编号
        String studentNumber = jwtUtil.parseToken(token);
        return resultRepository.findByStudentNumber(studentNumber);
    }
//xyy
    public List<Results> getAllResults() {
        return resultRepository.findAll();
    }

    public Results getResultById(String id) {
        return resultRepository.findById(id).orElse(null);
    }

    public Results saveResult(Results result) {
        return resultRepository.save(result);
    }

    public void deleteResult(String id) {
        resultRepository.deleteById(id);
    }

}

